package com.spring.nio.core.exception;

import com.spring.nio.core.configuration.NioServerBootstrap;
import com.spring.nio.core.event.listener.event.ExceptionEvent;
import com.spring.nio.core.event.listener.event.constant.EventSourceTypeEnum;
import com.spring.nio.core.event.listener.event.model.EventSource;
import com.spring.nio.core.event.listener.manage.ApplicationEventDispatchManager;
import org.springframework.context.ApplicationEvent;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author: YSFY
 * @date: 2021-03-24 14:31
 * @pacage_name: com.spring.nio.core.exception
 * @class_name: ExceptionManager
 * @description: 异常管理器
 */

public class ExceptionManager {

    /**
     * 异常处理器
     * @param
     * */
    public static void handleException(EventSource eventSource) {
        try {
            Constructor constructor = eventSource.getEventClass().getConstructor(Object.class);
            constructor.setAccessible(Boolean.TRUE);
            ApplicationEventDispatchManager.publishEvent((ApplicationEvent) constructor.newInstance(new Object[]{eventSource}));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
